#define _CRT_SECURE_NO_WARNINGS 1

#include <vector>
using namespace std;
#include <algorithm>

class Solution
{
    vector<vector<int>> ret;
    vector<int> path;
    bool check[8] = { false };
public:
    vector<vector<int>> permuteUnique(vector<int>& nums)
    {
        sort(nums.begin(), nums.end());
        dfs(nums, 0);
        return ret;
    }

    void dfs(vector<int>& nums, int pos)
    {
        if (path.size() == nums.size())
        {
            ret.push_back(path);
            return;
        }

        for (int i = 0; i < nums.size(); i++)
        {
            if (check[i] == false && (i == 0 || nums[i] != nums[i - 1] || check[i - 1] == true))
            {
                path.push_back(nums[i]);
                check[i] = true;
                dfs(nums, pos);
                path.pop_back();
                check[i] = false;
            }
        }
    }
};

class Solution {
public:
    int maxArea(vector<int>& height)
    {
        int ret = 0;
        int left = 0, right = height.size() - 1;
        while (left < right)
        {
            int x = min(height[left], height[right]);
            ret = max(ret, x * (right - left));

            if (height[left] < height[right])
                left++;
            else
                right--;
        }
        return ret;
    }
};